#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'sundx'

stations = {
    'kone': {'id', 'nv', 'ut'},
    'ktwo': {'wa', 'id', 'mt'},
    'kthree': {'or', 'nv', 'ca'},
    'kfour': {'nv', 'ut'},
    'kfive': {'ca', 'az'}
}

statesNeeded = {'mt', 'wa', 'or', 'id',
                'nv', 'ut', 'ca', 'az'}
# 存储最终选择的广播台
finalStations = []
# 循环至需要的洲 为空
while statesNeeded:
    # stations 列表内需要的 站台
    bestStations = None
    # 已经覆盖的洲
    stationsCoverd = ()
    # 对于stations 列表内剩余的元素
    for station, states in stations.items():
        # 对剩余需要的洲与当前广播覆盖的洲 取交
        Coverd = statesNeeded & states
        # 用覆盖面更大的替换掉覆盖面更小的（针对未被覆盖的洲）
        if len(Coverd) > len(stationsCoverd):
            bestStations = station
            stationsCoverd = Coverd
    # 去除已经覆盖的洲
    statesNeeded -= stationsCoverd

    finalStations.append(bestStations)

print(finalStations)
